<?php

namespace App\Service\Message;

use App\Cache\UserRemarkCache;
use App\Constants\ErrorCode;
use App\Helpers\AliyunUtil;
use App\Helpers\ConfigUtil;
use App\Model\UserCoin;
use App\Model\UserSocialProfile;
use App\Model\UserTag;
use App\Model\VideoCall;
use App\Model\VoiceCall;
use App\Service\CallBaseService;
use App\Service\ServiceTrait\GetUserInfoTrait;

class QuickCallUserService extends CallBaseService
{
    use GetUserInfoTrait;
    public function handle()
    {
        $userId = $this->getUserId();
        $callType = $this->request->input('call_type', 1);

        //获取指定的主播
        $hostId = $this->getHostsForMatch($userId, 1, $callType);
        if (!$hostId) {
            $hostId = $this->getHostsForMatch($userId, -1, $callType);
            if (!$hostId) return $this->setError(ErrorCode::NO_VALID_HOST, '当前主播均在忙碌中，请稍后再试~');
        }


        $hostProfile = $this->getUserInfo($hostId);

        $socialTags = UserSocialProfile::getBatchProfile([$hostId], 'tag');
        $video = $hostProfile->video ? json_decode($hostProfile->video, true) : [];

        //个人展示图
        $bigPosters = $posters = !$hostProfile->poster ? [] : explode(',', trim($hostProfile->poster, ','));
        foreach ($bigPosters as &$poster) {
            $poster = AliyunUtil::imageResize(AliyunUtil::IMG_HOST . $poster);
        }

  	//暂下掉弹出功能
        return [];
	
	/*
	return [
            'avatar' => $hostProfile->avatar,
            'user_id' => $hostId,
            'nick_name' => $hostProfile->nick_name,
            'big_poster' =>  $bigPosters ?: [$hostProfile->avatar],
            'coin' => $callType == VoiceCall::CALL_TYPE ? $hostProfile->coin_setting : $hostProfile->video_coin_setting,
            'remark' => (new UserRemarkCache())->getRemark($userId, $hostId),
            'video_link' => $video ? AliyunUtil::VOICE_HOST . $video['link'] : '',
            'tags' => array_merge(
                [$hostProfile['age'].'岁'],
                $socialTags[$hostId] ?? []
            )
    	];*/
    }
}
